package com.lemon.smartsafety.ui.adapter.safe.data;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.app.DataInfo;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingCheckItemFlowVo;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Cooliean on 16/3/29.
 */
public class BuildingCheckItemFlowAdapter extends LemonRcvAdapter<CompanyBuildingCheckItemFlowVo> {
    public BuildingCheckItemFlowAdapter(@Nullable List<CompanyBuildingCheckItemFlowVo> data) {
        super(data);
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new BuildingCheckItemFlowItem();
    }

    public class BuildingCheckItemFlowItem implements AdapterItem<CompanyBuildingCheckItemFlowVo> {

        CardView     mainCardView;
        TextView     tvTitle;
        TextView     tvMustCheck;
        TextView     tvConclusion;
        TextView     tvRemark;
        LinearLayout llRemark;


        private CompanyBuildingCheckItemFlowVo mData;
        private int                            mPosition;

        @Override
        public int getLayoutResId() {
            return R.layout.item_check_item_flow;
        }

        @Override
        public void bindViews(View root) {
            mainCardView = (CardView) root.findViewById(R.id.main_card_view);
            tvTitle = (TextView) root.findViewById(R.id.tv_title);
            tvMustCheck = (TextView) root.findViewById(R.id.tv_must_check);
            tvConclusion = (TextView) root.findViewById(R.id.tv_conclusion);
            tvRemark = (TextView) root.findViewById(R.id.tv_remark);
            llRemark = (LinearLayout) root.findViewById(R.id.ll_remark);
        }

        @Override
        public void setViews() {
        }

        @Override
        public void handleData(CompanyBuildingCheckItemFlowVo data, int position) {
            mData = data;
            mPosition = position;
            tvTitle.setText(StringUtils.nullValue(data.getFlowName()));


            if (StringUtils.getBoolean(data.getIsIgnore())) {
                tvMustCheck.setText(DataInfo.getStatusString("不需", DataInfo.ColorStatus.STATUS_GRAY));
            } else {
                tvMustCheck.setText(DataInfo.getStatusString("必须", DataInfo.ColorStatus.STATUS_RED));
            }

            String conclusionTitle = StringUtils.nullValue(data.getConclusionTitle(), "无");
            tvConclusion.setText(conclusionTitle.trim());
            String remarkTitle = StringUtils.nullValue(data.getCheckWay());
            if (remarkTitle.length() == 0) {
                llRemark.setVisibility(View.GONE);
            } else {
                llRemark.setVisibility(View.VISIBLE);
            }
            tvRemark.setText(StringUtils.nullValue(data.getCheckWay(), "无"));

        }
    }
}
